package edu.taru.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.naming.directory.SearchControls;

import edu.taru.dao.DeleteDaoImpl;
import edu.taru.dao.EchoDaoImpl;
import edu.taru.dao.LoginDaoImpl;
import edu.taru.dao.RegisterDaoImpl;
import edu.taru.dao.SearchDaoImpl;
import edu.taru.dao.UpdateDaoImpl;
import edu.taru.dao.UpdatePasswordDaoImpl;
import edu.taru.dao.RefreshDaoImpl;
import edu.taru.pojo.User;

public class Services {
	static List<User> list = new ArrayList<User>();
	/**
	 * 登录
	 * @param username
	 * @param password
	 * @return
	 */
	public User login(String username,String password) {
		LoginDaoImpl loginDaoImpl = new LoginDaoImpl();
		list.add(loginDaoImpl.select(username, password));
		return loginDaoImpl.select(username, password);
	}
	/**
	 * 注册
	 * @param user
	 */
	
	public void register(User user) {
		// TODO Auto-generated method stub
		RegisterDaoImpl registerDaoImpl = new RegisterDaoImpl();
		registerDaoImpl.insert(user);
	}
	/**
	 * 查看全部用户
	 */
	public Vector<Vector<String>> refresh(){
		RefreshDaoImpl refreshDaoImpl = new RefreshDaoImpl();
		return refreshDaoImpl.select();
	}
	
	/**
	 * 查询单个用户
	 */
	public Vector<Vector<String>> search(String username){
		SearchDaoImpl searchDaoImpl = new SearchDaoImpl();
		return searchDaoImpl.select(username);
	}
	/**
	 * 删除用户
	 * @param id
	 */
	public void delete(String id) {
		DeleteDaoImpl deleteDaoImpl = new DeleteDaoImpl();
		deleteDaoImpl.delete(id);
	}
	/**
	 * 获取当前登录的用户
	 * @return
	 */
	public User getLogined() {
		return list.get(0);
	}
	/**
	 * 修改信息
	 * @param user
	 */
	public void update(User user) {
		UpdateDaoImpl updateDaoImpl = new UpdateDaoImpl();
		updateDaoImpl.update(user);
	}
	public User update1(String id) {
		EchoDaoImpl echoDaoImpl = new EchoDaoImpl();
		User user = echoDaoImpl.echo(id);
		return user;
		
	}
	
	
	
}
